package com.wlz.rocketmq.filtermessage;

import com.wlz.rocketmq.constant.Constants;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

/**
 *  过滤消息 -- 生产者
 *
 *   按 sql 过滤
 *
 * @author wlz
 * @date 2022-07-02  3:51 下午
 */
@Slf4j
public class SqlFilterProducer {

    public static void main(String[] args) throws Exception{

        DefaultMQProducer producer = new DefaultMQProducer("SqlFilterProducer");

        producer.setNamesrvAddr(Constants.NAMESVADDR);
        producer.start();

        String[] tags = new String[] {"TagA", "TagB", "TagC"};

        for (int i = 0; i < 15; i++) {
            Message msg = new Message("SqlFilterTopic", tags[i % tags.length], ("hello world" + i).getBytes(RemotingHelper.DEFAULT_CHARSET));

            msg.putUserProperty("a", String.valueOf(i));

            SendResult send = producer.send(msg);

            log.info("SqlFilterProducer SendResult : {}", send);

        }

        producer.shutdown();

    }
}
